//输入10个复数放在结构体数组，根据模的大小排序输出

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define N 10

struct xx
{
	float r1;
	float r2;
	float m;
}s[N],*p,temp;

void sort(struct xx *p );
void swap(struct xx *a,struct xx *b);

void main()
{
	int i;
	p = s;
	srand(time(NULL));
	for (i=0;i<N;i++)
	{
		(p+i)->r1 = rand()%1000*0.1;
		(p+i)->r2 = rand()%1000*0.1;
		(p+i)->m = sqrt(pow(((p+i)->r1),2)+pow(((p+i)->r2),2));
	}
	for (i=0;i<N;i++)
		printf("%6.2f %6.2f %6.2f \n",(p+i)->r1,(p+i)->r2,(p+i)->m);
	printf("==========================\n");
	sort(p);

	for (i=0;i<N;i++)
                printf("%6.2f %6.2f %6.2f \n",(p+i)->r1,(p+i)->r2,(p+i)->m);
}
void sort(struct xx *p)
{	
	int i,k,j;
	for (i=0;i<N-1;i++)
       	{
               	k=i;
               	for (j=i+1;j<N;j++)
               	{
                       	if ((p+j)->m > (p+k)->m)
                       	        k=j;
               	}
               	swap((p+i),(p+k));
       	}
}

void swap(struct xx *a ,struct xx *b)
{
	temp = *a;
	*a = *b;
	*b = temp;
}





